package algotithm.leetcode.dp.hot.test53;

/**
 * @author zhouyanxiang
 * @Date 2021-02-2021/2/8-23:03
 * @Title 53. 最大子序和
 * @URL https://leetcode-cn.com/problems/maximum-subarray/
 */
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] arr = {-2,1,-3,4,-1,2,1,-5,4};
        int i = solution.maxSubArray(arr);
        System.out.println(i);
    }

    public int maxSubArray(int[] nums) {
        int res = nums[0];
        int sum = 0;
        for (int i = 0; i < nums.length; i++) {
            sum = Math.max(sum + nums[i],nums[i]);
            res = Math.max(sum,res);
        }
        return res;
    }


}
